home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / UPC12BS1.ZIP / MAIL / MLIB.C < prev    next >
C/C++ Source or Header  |  1993-09-20  |  15KB  |  436 lines

  1. /*--------------------------------------------------------------------*/
  2. /*       m l i b . c                                                  */
  3. /*--------------------------------------------------------------------*/
  4.  
  5. /*--------------------------------------------------------------------*/
  6. /*       Changes Copyright (c) 1989-1993 by Kendra Electronic         */
  7. /*       Wonderworks.                                                 */
  8. /*                                                                    */
  9. /*       All rights reserved except those explicitly granted by       */
  10. /*       the UUPC/extended license agreement.                         */
  11. /*--------------------------------------------------------------------*/
  12.  
  13. /*--------------------------------------------------------------------*/
  14. /*                          RCS Information                           */
  15. /*--------------------------------------------------------------------*/
  16.  
  17. /*
  18.  *    $Id: mlib.c 1.6 1993/09/20 04:39:51 ahd Exp $
  19.  *
  20.  *    Revision history:
  21.  *    $Log: mlib.c $
  22.  * Revision 1.6  1993/09/20  04:39:51  ahd
  23.  * OS/2 2.x support
  24.  *
  25.  * Revision 1.5  1993/08/11  02:31:12  ahd
  26.  * Use standard denormalize() macro for slash --> back slashes
  27.  *
  28.  * Revision 1.4  1993/08/03  03:11:49  ahd
  29.  * Further Windows 3.x fixes
  30.  *
  31.  * Revision 1.3  1993/07/31  16:26:01  ahd
  32.  * Changes in support of Robert Denny's Windows support
  33.  *
  34.  *
  35.  * 13 May 89      Use PC format path names for editor
  36.  * 01 Oct 89      Make Console_fgets use far pointers
  37.  *                Alter Console_fgets and Is_Console to type boolean
  38.  *
  39.  * 29 Jul 90      Use PC format path names for pager
  40.  */
  41.  
  42. /*
  43.    ibmpc/mlib.c   by <skl@van-bc.UUCP>   August/87
  44.  
  45.    Mailer UA system-dependent library
  46.  
  47.    Services to provide in mlib.c:
  48.  
  49.    Get a single character from the console.
  50.    Invoke the local editor on a given file.
  51.    Determine if a given file stream points to the console.
  52.    Get a line from the console.
  53.    Invoke a local pager on a given file.
  54.  
  55. */
  56.  
  57. /*--------------------------------------------------------------------*/
  58. /*                        System include files                        */
  59. /*--------------------------------------------------------------------*/
  60.  
  61. #include <stdlib.h>
  62. #include <stdio.h>
  63. #include <string.h>
  64. #include <conio.h>
  65. #include <io.h>
  66. #include <dos.h>
  67.  
  68. #if defined(WIN32)
  69. #include <windows.h>
  70. #endif
  71.  
  72. /*--------------------------------------------------------------------*/
  73. /*                    UUPC/extended include files                     */
  74. /*--------------------------------------------------------------------*/
  75.  
  76. #include "lib.h"
  77. #include "hlib.h"
  78. #include "execute.h"
  79.  
  80. /*--------------------------------------------------------------------*/
  81. /*                    Set up for console services                     */
  82. /*--------------------------------------------------------------------*/
  83.  
  84. #if defined(FAMILYAPI) || defined(BIT32ENV) || defined(_Windows)
  85. #define SIMPLE_CONSOLE_FGETS
  86. #else
  87.  
  88. #define MULTIPLEX 0x2f        /* 8086 DOS Interrupt for multiplexing */
  89.  
  90. static int DOSRead( char *buff, const int buflen);
  91.  
  92. static boolean DOSKeyActive( void );
  93.  
  94. static int DOSKeyRead( char *buff , int buflen );
  95.  
  96. #endif
  97.  
  98. /*--------------------------------------------------------------------*/
  99. /*       G e t _ O n e                                                */
  100. /*                                                                    */
  101. /*       Get a single character from the console                      */
  102. /*--------------------------------------------------------------------*/
  103.  
  104. int Get_One()
  105. {
  106.  
  107.    return getch();
  108.  
  109. } /*Get_One*/
  110.  
  111. /*--------------------------------------------------------------------*/
  112. /*       I n v o k e                                                  */
  113. /*                                                                    */
  114. /*       Invoke the user's editor or pager to handle a text file      */
  115. /*--------------------------------------------------------------------*/
  116.  
  117. int Invoke(const char *ecmd, const char *filename)
  118. {
  119.    char command[FILENAME_MAX*2 + 1];
  120.    char tempname[FILENAME_MAX];
  121.  
  122.    if (ecmd == nil(char))
  123.    {
  124.       printf("Invoke: No program specified to invoke.\n");
  125.       return 1;
  126.    }
  127.  
  128.    strcpy(tempname,filename);
  129.    denormalize( tempname );
  130.  
  131.    sprintf(command, ecmd, tempname);
  132.  
  133.    if(executeCommand(command, NULL, NULL, TRUE, TRUE ) != 0)
  134.    {
  135.       printf("Invoke: \"%s\" failed.\n", command);
  136.       return(2);
  137.    }
  138.  
  139.    return 0;
  140.  
  141. } /* Invoke */
  142.  
  143. /*--------------------------------------------------------------------*/
  144. /*       I s _ C o n s o l e                                          */
  145. /*                                                                    */
  146. /*       Determine if stream is from the console                      */
  147. /*                                                                    */
  148. /*       Note:  isatty() actually returns if the stream is a          */
  149. /*       character device, thus causing device NUL to appear          */
  150. /*       interactive; this is not acceptable, but there is not a      */
  151. /*       trivial fix.                                                 */
  152. /*--------------------------------------------------------------------*/
  153.  
  154. boolean Is_Console(FILE *stream)
  155. {
  156.  
  157.    return isatty(fileno(stream));
  158.  
  159. } /*Is_Console*/
  160.  
  161. #ifdef SIMPLE_CONSOLE_FGETS
  162.  
  163. /*--------------------------------------------------------------------*/
  164. /*       C o n s o l e _ f g e t s                                    */
  165. /*                                                                    */
  166. /*       Read a full line from the console under non-DOS systems      */
  167. /*--------------------------------------------------------------------*/
  168.  
  169. boolean Console_fgets(char *buff, int buflen, char *prompt)
  170. {
  171.  
  172.    if (bflag[F_DOSKEY] )
  173.    {
  174.      printmsg(0,"DOSKEY support not available, option disabled");
  175.      bflag[F_DOSKEY] = FALSE;
  176.    }
  177.  
  178.    fputs(prompt, stdout);
  179.  
  180.    return (fgets(buff, buflen, stdin) != nil(char)) ? TRUE : FALSE;
  181.  
  182. } /*Console_fgets*/
  183.  
  184. #else
  185.  
  186. /*--------------------------------------------------------------------*/
  187. /*       C o n s o l e _ f g e t s                                    */
  188. /*                                                                    */
  189. /*       Get a line of input from the local console                   */
  190. /*                                                                    */
  191. /*       This is a hook to allow for using the local system's         */
  192. /*       facility for input line editing.  We call DOS to perform     */
  193. /*       a line read, thus allowing utilities like DOSEDIT or CED     */
  194. /*       to do their fancy work.                                      */
  195. /*--------------------------------------------------------------------*/
  196.  
  197. boolean Console_fgets(char *buff, int buflen, char *prompt)
  198. {
  199.    static boolean eof = FALSE;    /* pending EOF flag  */
  200.  
  201.    char *eofptr;
  202.  
  203.    if (eof) {           /* have a pending EOF?  */
  204.       eof = FALSE;      /* no more pending EOF  */
  205.       return FALSE;     /* signal the EOF    */
  206.    }
  207.  
  208. /*--------------------------------------------------------------------*/
  209. /*      Prompt the user, read the data, and then go to a new line     */
  210. /*--------------------------------------------------------------------*/
  211.  
  212.    fputs(prompt, stdout);
  213.  
  214.    if ( DOSKeyActive() )
  215.       buflen = DOSKeyRead( buff, buflen );
  216.    else
  217.       buflen = DOSRead( buff, buflen );
  218.     putchar('\n');
  219.  
  220. /*--------------------------------------------------------------------*/
  221. /*             Determine if we hit end of file on the read            */
  222. /*--------------------------------------------------------------------*/
  223.  
  224.    if ( buflen == -1 )
  225.    {
  226.       *buff = '\0';
  227.       return FALSE;
  228.    }
  229.  
  230. /*--------------------------------------------------------------------*/
  231. /*                        Terminate the buffer                        */
  232. /*--------------------------------------------------------------------*/
  233.  
  234.    buff[buflen